(function(d) {
    var b = mobiscroll,
        a = b.$,
        c = b.classes;
    c.Widget = function(h, i, k) {
        function j(b) {
            a('.mbsc-fr-c', b);
            if (!a('.mbsc-fr-c', b).hasClass('mbsc-wdg-c') && mobiscroll.running) {
                a('.mbsc-fr-c', b).addClass('mbsc-wdg-c').append(e.show());
                if (!a('.mbsc-w-p', b).length) {
                    a('.mbsc-fr-c', b).addClass('mbsc-w-p');
                }
            }
        }
        var b, f, g, e = a(h),
            d = this;
        c.Frame.call(this, h, i, true);
        d._generateContent = function() {
            return '';
        };
        d._markupReady = function(a) {
            if (b.display != 'inline') {
                j(a);
            }
        };
        d._markupInserted = function(a) {
            if (b.display == 'inline') {
                j(a);
            }
            a.trigger('mbsc-enhance', [{
                theme: b.theme,
                lang: b.lang
            }]);
        };
        d._markupRemove = function() {
            e.hide();
            if (f) {
                f.prepend(e);
            } else {
                g.after(e);
            }
        };
        d._processSettings = function() {
            b = d.settings;
            d.buttons.close = {
                text: b.closeText,
                handler: 'cancel'
            };
            d.buttons.ok = {
                text: b.okText,
                handler: 'set'
            };
            b.buttons = b.buttons || (b.display == 'inline' ? [] : ['ok']);
            b.cssClass = (b.cssClass || '') + ' mbsc-wdg';
            if (!f && !g) {
                g = e.prev();
                if (!g.length) {
                    f = e.parent();
                }
            }
            e.hide();
        };
        if (!k) {
            d.init(i);
        }
    };
    c.Widget.prototype = {
        _hasDef: true,
        _hasTheme: true,
        _hasContent: true,
        _class: 'widget',
        _defaults: a.extend({}, c.Frame.prototype._defaults, {
            okText: 'OK'
        })
    };
    b.themes.widget = b.themes.frame;
    b.presetShort('widget', 'Widget', false);
}());